package com.bmft;

        import androidx.appcompat.app.AlertDialog;
        import androidx.appcompat.app.AppCompatActivity;

        import android.content.DialogInterface;
        import android.content.Intent;
        import android.os.Bundle;
        import android.view.View;

public class AlertDialogActivity14 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alert_dialog14);
    }

    public void backToMain(View view) {
        Intent intent = new Intent(AlertDialogActivity14.this, MainActivity.class);
        startActivity(intent);
    }

    public void AlertDialog(View view) {
        //新建弹窗对象。
        AlertDialog.Builder dialog = new AlertDialog.Builder (AlertDialogActivity14.this);
        dialog.setTitle("title of the dialog.");
        dialog.setMessage("message of the dialog.");
        //设置不能通过返回取消.
        dialog.setCancelable(false);
        //我们实现确认和取消方法，但是不设置方法的内容.
        dialog.setPositiveButton("positiveButton", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //确定发生的事件
            }
        });
        dialog.setNegativeButton("nagativeButton", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //取消发生的事件.
            }
        });
        //重要重要 最后 要show
        dialog.show();
    }
}